using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace MicroStar.Samples
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        private GraphicsDeviceManager graphics;
        private SpriteBatch spriteBatch;
        private ParticleEffect effect;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // First we need to load the particle effect from the XML file.
            effect = Content.Load<ParticleEffect>("ParticleEffects/ScreenBurn");
            // Then call the LoadContent to initialize the particle array and load the textures.
            effect.LoadContent(Content);

            // ******
            // Alternativately, we can create the effect programmatically.
            // Once you have a fully initialized ParticleEffect object, you can use the Save method to export to XML.
            // ******
//            effect = new ParticleEffect();
//            effect.ParticleLifespan = 800;
//            effect.MaxParticles = 1000;
//            effect.Textures.Add(@"Textures\smoke");
//            effect.Textures.Add(@"Textures\fire");
//            effect.Modifiers.Add(new AlphaAgeTransform());
//            effect.Modifiers.Add(new DirectionalPull { Gravity = new Vector2(0, -5) });
//            effect.Emitter = new RectEmitter { EmitAmount = 25, Width = GraphicsDevice.Viewport.Width + 100, Height = 10 };
//            effect.LoadContent(Content);
//#if WINDOWS
//            effect.Save(@"C:\Users\Jason\Desktop\effect.xml");
//#endif
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                Exit();

            Vector2 emitPosition = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height + 15);
            effect.Emit(gameTime, emitPosition);

            effect.Update(gameTime);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            effect.Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
